/*
 * SteepTimer - A timer designed for tea fanatics
 * Copyright (C) 2011  Wesley Crossman
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#ifndef TEASOUND_H
#define TEASOUND_H

#include <QDir>
#include <QUrl>
#include <QStringList>
#include <phonon/phononnamespace.h>

namespace Phonon {
    class MediaObject;
    class MediaSource;
    class AudioOutput;
}

struct SoundSettings {
    SoundSettings(const QString &filename, const QString &title, const QString &author,
                  const QString &url, const QString &licenseUrl) :
                m_filename(filename),
                m_title(title),
                m_author(author),
                m_url(url),
                m_licenseUrl(licenseUrl) {
    }
    SoundSettings(const QStringList &list) :
                m_filename(list[0]),
                m_title(list[1]),
                m_author(list[2]),
                m_url(list[3]),
                m_licenseUrl(list[4]) {
    }
    QString m_filename, m_title, m_author;
    QUrl m_url, m_licenseUrl;
};

class TeaSound : public QObject {
Q_OBJECT
public:
    static TeaSound *instance();
    QDir getSoundDir() {return m_soundDir;}
    QList < SoundSettings > getSounds() {return m_soundList;}
    bool isPlaying();

public slots:
    void play(const QString &filename = QString());
    void enqueue(const QString &filename = QString());
    void stop();

private:
    static TeaSound *m_instance;
    Phonon::AudioOutput *m_aoutput;
    Phonon::MediaObject *m_mobject;
    QDir m_soundDir;
    QList < SoundSettings > m_soundList;
    explicit TeaSound();
    Phonon::MediaSource *load(const QString &filename);

signals:
    void aboutToFinish();
    void stateChanged(Phonon::State newstate, Phonon::State oldstate);

};




#endif // TEASOUND_H
